<template>
  <div>
    <el-dialog title="撤回缴费凭证" :visible.sync="isShow" center  append-to-body>
      <el-form :model="form" :rules="rules" ref="ruleForm" label-position="left" label-width="120px">
        <el-form-item label="撤回原因" prop="reason">
          <el-input v-model="form.reason" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" >
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="submint">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data () {
    return {
      isShow: false,
      form: {
        reason: ''
      },
      rules: {
        reason: [
          { required: true, message: '请输入撤回原因', trigger: 'change' }
        ]
      },
      id: null
    }
  },
  methods: {
    show(data) {
      this.isShow = true
      this.id = data.id
    },
    submint() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          this.submitPost()
        } else {
          return false;
        }
      })
    },
    submitPost() {
      let params = {
        finals: this.id,
        reason: this.form.reason
      }
      this.$axios.post(`api/finals/${this.id}/revoke_pay_img`, params).then(
        res => {
          if (res.data.code == 200) {
            this.$message({
              type: 'success',
              message: '撤回缴费凭证成功！'
            })

            this.close()
            setTimeout(() => {
              this.$emit('refresh')
            }, 300)
          } else {
            this.$message.error({
              message: res.data.message
            })
          }
        }
      )
    },
    close() {
      this.$refs['ruleForm'].resetFields()
      this.isShow = false
    }
  }
}
</script>

<style lang='less' type='text/css'>

</style>
